$(()=>{
    let code;
    $("#sendMail").click(()=>{
        $("#first").addClass("el-loading");
        let email=$("#email").val();
        $.post("{LINK_user/basic/setemail/sendMail}",{
            email:email
        },text=>{
            $("#first").removeClass("el-loading");
            let data=JSON.parse(text);
            if(data.status){
                code=data.code;
                dialog("提示","邮件发送成功，请检查您的邮箱。");
            }else{
                dialog("错误","邮件发送失败");
            }
        })
    });
    $("#nextBtn").click(()=>{
        $("#first").addClass("el-loading");
        let email=$("#email").val();
        let code_val=$("#code").val();
        if(code_val==code){
            $.post("{LINK_user/basic/setemail/verify}",{
                email:email
            },text=>{
                $("#first").removeClass("el-loading");
                let data=JSON.parse(text);
                if(data.status){
                    $("#first").hide();
                    $("#next").show();
                    dialog("提示","邮箱验证成功，请填写新邮箱。");
                }else{
                    dialog("错误",data.msg);
                }
            });
        }else{
            $("#first").removeClass("el-loading");
            dialog("错误","验证码不正确");
        }
    });
    $("#finish").click(()=>{
        $("#next").addClass("el-loading");
        let email=$("#new-email").val();
        $.post("{LINK_user/basic/setemail}",{
            email:email
        },text=>{
            $("#next").removeClass("el-loading");
            let data=JSON.parse(text);
            if(data.status){
                dialog("错误","邮箱修改成功。");
                location.href="{LINK_user#basic}";
            }else{
                dialog("错误","邮箱修改失败："+data.msg);
            }
        });
    });
});